#ifndef SDSHIP_H
#define SDSHIP_H

#include <set>
#include <math.h>
#include "../src/chipmunk.h"
#include "sdObject.h"
#include "sdTimed.h"

//A ship object
class sdShip : public sdObject {
private:
    cpFloat hp_; //Hitpoints
	cpFloat hpMax_; //Max hitpoints
	
	int guns; //How many guns this ship has

	cpFloat gunReloads_[3]; //Reload times for the two guns
	cpFloat gunTimes_[3]; //How "reloaded" a gun is

	cpFloat deltaW_; //Turning speed, actually a factor(see implementation)
	cpFloat forwardsForce_; //How strong the thrusters are in a given direction
	cpFloat reverseForce_;
	cpFloat leftForce_;
	cpFloat rightForce_;

public:
	//Constructors
    inline sdShip(int hp, int hpMax) : sdObject(cpBodyNew(0, 0)), hp_(hp), hpMax_(hpMax) {
		gunReloads_[0] = 0.01;
		gunReloads_[1] = 0.6;
		gunReloads_[2] = 1.0;

		gunTimes_[0] = gunReloads_[0];
		gunTimes_[1] = gunReloads_[1];
		gunTimes_[2] = gunReloads_[2];

		guns = 3;
	}
   
    void move(const cpVect& direction); //direction of force, amp 1.0 is full in that direction
    void turn(const cpVect& direction); //turn to face this direction
    bool shoot(const int weapon, std::set<sdTimed*>* bullets); //try to shoot the passed in weapon
	
	void update(cpFloat ticks); //Update reload times
    
    inline void takeDamage(cpFloat damage) {hp_ -= damage;}
    inline cpFloat getHp() {return hp_;}
	inline cpFloat getMaxHp() {return hpMax_;}
    inline bool dead() {return hp_ <= 0;}
    
    void getChunks(std::set<sdTimed*>* chunks); //Gets chunks after ship is destroyed
    
    inline void setDeltaW(cpFloat deltaW) {deltaW_ = deltaW;}
    inline cpFloat getDeltaW() {return deltaW_;}
    
 	inline void setForwardsForce(cpFloat forwardsForce) {forwardsForce_ = forwardsForce;}
	inline cpFloat getForwardsForce() {return forwardsForce_;}
	
	inline void setReverseForce(cpFloat reverseForce) {reverseForce_ = reverseForce;}
	inline cpFloat getReverseForce() {return reverseForce_;}
	
	inline void setLeftForce(cpFloat leftForce) {leftForce_ = leftForce;}
	inline cpFloat getLeftForce() {return leftForce_;}
	
	inline void setRightForce(cpFloat rightForce) {rightForce_ = rightForce;}
	inline cpFloat getRightForce() {return rightForce_;}
};

#endif
